<?php 
//Start session
	@session_start();
	
	//Include database connection details
	require_once('inc/config.inc');
	
	
	
	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	$select = mysql_query("SELECT file_name FROM material_file where material_id = '".$_GET['mat_id']."'");
	$query = mysql_query("delete from course_materials where material_id='".$_GET['mat_id']."'");
	if($query){
			while($row = mysql_fetch_array($select)){
				unlink("../uploads/".$row[0]);
			}
	}
	else {
		echo mysql_error();
	}	
?>